package com.sinog.core.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.HashMap;
import java.util.Map;

/**
 * @desc 分页返回封装
 * @author lzq
 * @date 2022/5/8 17:35
 */
public final class PageReturnUtil {

    /**
     * 返回结果字符串
     * @param page page
     * @return String
     */
    public static String pageReturn(Page<Map<String,String>> page) {
        Map<String,Object> result = new HashMap<>(2);
        result.put("total",page.getTotal());
        result.put("data",page.getRecords());
        return JsonUtil.toText(result);
    }

    /**
     * 返回结果map
     * @param page page
     * @return Map<String,Object>
     */
    public static Map<String,Object> pageReturnMap(Page<Map<String,String>> page) {
        Map<String,Object> result = new HashMap<>(2);
        result.put("total",page.getTotal());
        result.put("data",page.getRecords());
        return result;
    }
}